<<<<<<< HEAD
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<meta content="yes" name="apple-mobile-web-app-capable">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<meta content="telephone=no" name="format-detection">
	<meta content="no-cache" http-equiv="Cache-Control">
	<title>源之东方</title>
	<link href="__STATIC__/css/shopin.css" rel="stylesheet"/>
	<link rel="stylesheet" href="__STATIC__/css/ydui.css?rev=@@hash">
	<link rel="stylesheet" href="__STATIC__/css/shopins.css" />
	<link rel="stylesheet" href="__STATIC__/css/demo.css">
	<style>
		* { touch-action: pan-y; }
	</style>
</head>
<body>
<div class="header">
	<div class="left"><a href="javascript:;" class="a-back"><span>返回</span></a></div>
	<div class="center">
		<h1>管理收货地址</h1>
	</div>
</div><!--//头部结束-->
<div class="content">
	<div class="m-address">
		{volist name="addrInfo" id="vo"}
		<div class="address manage-address" id="addr{$vo.id}">
			<div class="info">
				收货人：<p class="name">{$vo.consignee}</p>
				<p class="phone">{$vo.mobile}</p>
			</div>
			<div class="details">收货地址：{$vo.province}{$vo.city}{$vo.country}{$vo.detail}</div>
			<div class="address-bottom">
				{if condition = "$vo.default_address == 1"}
				<label><input type="radio" name="address" value="{$vo.id}" checked>默认收货地址</label>
				{else}
				<label><input type="radio" name="address" value="{$vo.id}">默认收货地址</label>
				{/if}
				<div class="operate ">
					<a href="javascript:;" class="j-address-edit edit" data-id="{$vo.id}">编辑</a>｜<a href="javascript:;" class="j-address-delete" onclick="delAddress({$vo.id})">删除</a>
				</div>
			</div>
		</div><!-- //收货地址 -->
		{/volist}
	</div>
	<div class="form-view address-view edit-address">
		<input type="hidden" name="addrId">
		<div class="f-row">
			<label class="f-label"><em>*</em>收货人姓名</label>
			<div class="f-main">
				<input id="name" type="text" placeholder="请填写收货人姓名">
			</div>
		</div>
		<div class="f-row">
			<label class="f-label"><em>*</em>电话/手机</label>
			<div class="f-main">
				<input id="phone" type="tel" placeholder="请填写电话号码">
			</div>
		</div>
		<div class="f-row">
			<label class="f-label"><em>*</em>请选择地址</label>
			<section class="g-scrollview">
				<div class="m-cell">
					<div class="cell-item">
						<div class="cell-right cell-arrow">
							<input type="text" class="cell-input" readonly id="J_Address" placeholder="请选择收货地址">
						</div>
					</div>
				</div>
			</section>
		</div>
		<div class="f-row">
			<label class="f-label"><em>*</em>详细地址</label>
			<div class="f-main">
				<textarea id="addressDetail" placeholder="请填写详细地址" max-length="200"></textarea>
			</div>
		</div>
	</div>
	<button id="actionBtn">新增收货地址</button>
	<input type="hidden" name="user_id" value="{$Think.session.Auth.Uid}">
</div>

<script src="__STATIC__/js/zepto.min.js"></script>
<!--<script type="text/javascript" src="__STATIC__/js/base.min.js"></script>-->
<script src="__STATIC__/js/shopin.js"></script>
<script type="text/javascript" src="__STATIC__/js/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/js/ydui.citys.js"></script>
<script type="text/javascript" src="__STATIC__/js/ydui.js"></script>
<script>

//    console.log($("#addr67").find('.name').html('haha'));


    $('#actionBtn').on('click', function(){
//	loading();//显示loading方法  关闭：closeLoad()
        if($('.m-address').is(':visible') && $('.edit-address').is(':hidden')){
            $('.m-address').css('display','none');
            $('.edit-address').css('display','block');
            $(this).text('保存地址');
        }else{
            if($("#name").val() == ""){
                alert('你没写名字！');
                $("#name").focus();
                return false;
            }
            if($("#phone").val() == ""){
                alert('你没写电话！');
                $("#phone").focus();
                return false;
            }
            if($("#J_Address").val() == ""){
                alert('请填写收货地址！');
                $("#J_Address").focus();
                return false;
            }
            if($("#addressDetail").val() == ""){
                alert('请填写详细地址！');
                $("#addressDetail").focus();
                return false;
            }
            $('.m-address').css('display','block');
            $('.edit-address').css('display','none');
            $(this).text('新增收货地址');
            newAddress();
        }
    });
    function newAddress(){
        var addrId = $("input[name = 'addrId']").val();
        var _name = $('#name').val();
        var _phone = $('#phone').val();
		var _address = $('#J_Address').val();
        var _addressDetail = $('#addressDetail').val();
        var _html = "<div class=\"address confirm-address\"><div class=\"info\">收货人：<p class=\"name\">" + _name + "</p><p class=\"phone\">" + _phone + "</p></div><div class=\"details\">收货地址：" + _address + _addressDetail + "</div></div>";
        $('.j_myaddress').append(_html);
        //ajax保存地址
        if(addrId == ''){
            var data = {
                'user_id' : $("input[name = 'user_id']").val(),
                'name' : _name,
                'phone' : _phone,
                'address' : _address,
                'addressDetail' : _addressDetail
            };
            insertAddress(data);
		}else{
            var data = {
                'id' : addrId,
                'user_id' : $("input[name = 'user_id']").val(),
                'name' : _name,
                'phone' : _phone,
                'address' : _address,
                'addressDetail' : _addressDetail
            };
            updateAddress(data);
		}

    };

    // 清空表单数据
    function clearAddress()
    {
        $("input[name = 'addrId']").val('');
        $('#name').val('');
        $('#phone').val('');
		$('#J_Address').val('');
        $('#addressDetail').val('');
    }

    // 添加收货地址
    function insertAddress(data)
    {
        $("input[type = 'radio']").attr('checked', '');
        $.ajax({
            type : 'post',
            dataType : 'json',
            url : '/myself/insertAddress',
            data : data,
            success:function(data)
            {
                if(data.status){
                    clearAddress();
                    var data = data.data;
                    var ele = $('.m-address');
                    console.log(data.default_address);
                    if(data.default_address == 1){
                        var html = '<div class="address manage-address" id="addr' + data.id + '"><div class="info">收货人：<p class="name">' + data.consignee + '</p><p class="phone">' + data.mobile + '</p>' +
                            '</div><div class="details">收货地址：' + data.province + data.city + data.country + data.detail + '</div><div class="address-bottom">' +
                            '<label><input type="radio" name="address" value="' + data.id + '" checked>默认收货地址</label><div class="operate "><a href="javascript:;"' +
                            ' class="j-address-edit edit" data-id="' + data.id + '">编辑</a>｜<a href="javascript:;" class="j-address-delete" onclick="delAddress(' + data.id + ')">删除</a>' +
                            '</div></div></div>';
                    }else{
                        var html = '<div class="address manage-address" id="addr' + data.id + '"><div class="info">收货人：<p class="name">' + data.consignee + '</p><p class="phone">' + data.mobile + '</p>' +
                            '</div><div class="details">收货地址：' + data.province + data.city + data.country + data.detail + '</div><div class="address-bottom">' +
                            '<label><input type="radio" name="address" value="' + data.id + '">默认收货地址</label><div class="operate "><a href="javascript:;"' +
                            ' class="j-address-edit edit" data-id="' + data.id + '">编辑</a>｜<a href="javascript:;" class="j-address-delete" onclick="delAddress(' + data.id + ')">删除</a>' +
                            '</div></div></div>';
                    }
                    ele.append(html);
                    $('.m-address').css('display','block');
                    $('.edit-address').css('display','none');
                    $('#actionBtn').text('新增收货地址');
                }else{
                    alert(data.message);
                }
            },
            error:function(error){
                console.log(error);
            }
        });
    }

    // 更新地址
    function updateAddress(data){
        $.ajax({
            type : 'post',
            dataType : 'json',
            url : '/myself/editAddress',
            data : data,
            success:function(data)
            {
				if(data.status){
                    clearAddress()
                    var data = data.data;
                    $("#addr" + data.id).find('.name').html(data.consignee);
                    $("#addr" + data.id).find('.phone').html(data.mobile);
                    $("#addr" + data.id).find('.details').html('收货地址：' + data.province + data.city + data.country + data.detail);
				}else{
				    alert(data.message);
				}
            },
            error:function(error){
                console.log(error);
            }
        });
    };

    // 编辑地址
    $('.edit').on('click',function(){
        if($('.m-address').is(':visible') && $('.edit-address').is(':hidden'))
        {
            $('.m-address').css('display','none');
            $('.edit-address').css('display','block');
            $('#actionBtn').text('编辑地址');
            var id = $(this).attr('data-id');
            $.ajax({
                type:"get",
                dataType:'json',
                data:{
					id : id
                },
                url:"/myself/detail",
                async:true,
                success:function(data){
					if(data){
					    $("input[name = 'addrId']").val(data.id);
                        $("#name").val(data.consignee);
                        $("#phone").val(data.mobile);
                        $("#J_Address").val(data.province + ' ' + data.city + ' ' + data.country);
                        $("#addressDetail").val(data.detail);
					}
                },
                error:function(error){
                    //异常处理；
                    console.log(error);
                }
            });
        }
    });

    // 删除地址
    function delAddress(id){
        var res = confirm('确定要删除收货地址吗?');
        if(res){
            $.ajax({
                type : 'get',
                dataType : 'json',
                url : '/myself/delAddr',
                data : {
                    'id' : id
                },
                success:function(data){
                    if(data.status){
                        $("#addr" + id).empty(); // 删除下面的所有子元素
                        $("#addr" + id).remove(); // 删除对象本身
                    }
                    else{
                        alert(data.message);
                    }
                },
                error:function(error){
                    console.log(error);
                }
            });
        }
    }

    // 选择收货地址处理
    $("input[type = 'radio']").on('click', function(){
        var id = $(this).val();
        changeAdder(id);
    });
    function changeAdder(id)
    {
        $.ajax({
            type : 'get',
            dataType : 'json',
            url : '/myself/changeAddress',
            data : {
                id : id,
                user_id : $("input[name='user_id']").val()
            },
            success : function(data){
                if(!data.status){
                    console.log('变更错误');
                }
            },
            error : function(error){
                console.log(error);
            }
        });
    }
</script>
<script>
    /**
     * 默认调用
     */
    !function () {
        var target = $('#J_Address');

        target.citySelect();

        target.on('click', function (event) {
            event.stopPropagation();
            target.citySelect('open');
        });

        target.on('done.ydui.cityselect', function (ret) {
            $(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
        });
    }();
</script>
</body>
</html>
=======
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
	<meta content="yes" name="apple-mobile-web-app-capable">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<meta content="telephone=no" name="format-detection">
	<meta content="no-cache" http-equiv="Cache-Control">
	<title>源之东方</title>
	<link href="__STATIC__/css/shopin.css" rel="stylesheet"/>
	<link rel="stylesheet" href="__STATIC__/css/ydui.css?rev=@@hash">
	<link rel="stylesheet" href="__STATIC__/css/shopins.css" />
	<link rel="stylesheet" href="__STATIC__/css/demo.css">
	<style>
		* { touch-action: pan-y; }
	</style>
</head>
<body>
<div class="header">
	<div class="left"><a href="javascript:;" class="a-back"><span>返回</span></a></div>
	<div class="center">
		<h1>管理收货地址</h1>
	</div>
</div><!--//头部结束-->
<div class="content">
	<div class="m-address">
		{volist name="addrInfo" id="vo"}
		<div class="address manage-address" id="addr{$vo.id}">
			<div class="info">
				收货人：<p class="name">{$vo.consignee}</p>
				<p class="phone">{$vo.mobile}</p>
			</div>
			<div class="details">收货地址：{$vo.province}{$vo.city}{$vo.country}{$vo.detail}</div>
			<div class="address-bottom">
				{if condition = "$vo.default_address == 1"}
				<label><input type="radio" name="address" value="{$vo.id}" checked>默认收货地址</label>
				{else}
				<label><input type="radio" name="address" value="{$vo.id}">默认收货地址</label>
				{/if}
				<div class="operate ">
					<a href="javascript:;" class="j-address-edit edit" data-id="{$vo.id}">编辑</a>｜<a href="javascript:;" class="j-address-delete" onclick="delAddress({$vo.id})">删除</a>
				</div>
			</div>
		</div><!-- //收货地址 -->
		{/volist}
	</div>
	<div class="form-view address-view edit-address">
		<input type="hidden" name="addrId">
		<div class="f-row">
			<label class="f-label"><em>*</em>收货人姓名</label>
			<div class="f-main">
				<input id="name" type="text" placeholder="请填写收货人姓名">
			</div>
		</div>
		<div class="f-row">
			<label class="f-label"><em>*</em>电话/手机</label>
			<div class="f-main">
				<input id="phone" type="tel" placeholder="请填写电话号码">
			</div>
		</div>
		<div class="f-row">
			<label class="f-label"><em>*</em>请选择地址</label>
			<section class="g-scrollview">
				<div class="m-cell">
					<div class="cell-item">
						<div class="cell-right cell-arrow">
							<input type="text" class="cell-input" readonly id="J_Address" placeholder="请选择收货地址">
						</div>
					</div>
				</div>
			</section>
		</div>
		<div class="f-row">
			<label class="f-label"><em>*</em>详细地址</label>
			<div class="f-main">
				<textarea id="addressDetail" placeholder="请填写详细地址" max-length="200"></textarea>
			</div>
		</div>
	</div>
	<button id="actionBtn">新增收货地址</button>
	<input type="hidden" name="user_id" value="{$Think.session.Auth.Uid}">
</div>

<script src="__STATIC__/js/zepto.min.js"></script>
<!--<script type="text/javascript" src="__STATIC__/js/base.min.js"></script>-->
<script src="__STATIC__/js/shopin.js"></script>
<script type="text/javascript" src="__STATIC__/js/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/js/ydui.citys.js"></script>
<script type="text/javascript" src="__STATIC__/js/ydui.js"></script>
<script>

//    console.log($("#addr67").find('.name').html('haha'));


    $('#actionBtn').on('click', function(){
//	loading();//显示loading方法  关闭：closeLoad()
        if($('.m-address').is(':visible') && $('.edit-address').is(':hidden')){
            $('.m-address').css('display','none');
            $('.edit-address').css('display','block');
            $(this).text('保存地址');
        }else{
            if($("#name").val() == ""){
                alert('你没写名字！');
                $("#name").focus();
                return false;
            }
            if($("#phone").val() == ""){
                alert('你没写电话！');
                $("#phone").focus();
                return false;
            }
            if($("#J_Address").val() == ""){
                alert('请填写收货地址！');
                $("#J_Address").focus();
                return false;
            }
            if($("#addressDetail").val() == ""){
                alert('请填写详细地址！');
                $("#addressDetail").focus();
                return false;
            }
            $('.m-address').css('display','block');
            $('.edit-address').css('display','none');
            $(this).text('新增收货地址');
            newAddress();
        }
    });
    function newAddress(){
        var addrId = $("input[name = 'addrId']").val();
        var _name = $('#name').val();
        var _phone = $('#phone').val();
		var _address = $('#J_Address').val();
        var _addressDetail = $('#addressDetail').val();
        var _html = "<div class=\"address confirm-address\"><div class=\"info\">收货人：<p class=\"name\">" + _name + "</p><p class=\"phone\">" + _phone + "</p></div><div class=\"details\">收货地址：" + _address + _addressDetail + "</div></div>";
        $('.j_myaddress').append(_html);
        //ajax保存地址
        if(addrId == ''){
            var data = {
                'user_id' : $("input[name = 'user_id']").val(),
                'name' : _name,
                'phone' : _phone,
                'address' : _address,
                'addressDetail' : _addressDetail
            };
            insertAddress(data);
		}else{
            var data = {
                'id' : addrId,
                'user_id' : $("input[name = 'user_id']").val(),
                'name' : _name,
                'phone' : _phone,
                'address' : _address,
                'addressDetail' : _addressDetail
            };
            updateAddress(data);
		}

    };

    // 清空表单数据
    function clearAddress()
    {
        $("input[name = 'addrId']").val('');
        $('#name').val('');
        $('#phone').val('');
		$('#J_Address').val('');
        $('#addressDetail').val('');
    }

    // 添加收货地址
    function insertAddress(data)
    {
        $("input[type = 'radio']").attr('checked', '');
        $.ajax({
            type : 'post',
            dataType : 'json',
            url : '/myself/insertAddress',
            data : data,
            success:function(data)
            {
                if(data.status){
                    clearAddress();
                    var data = data.data;
                    var ele = $('.m-address');
                    console.log(data.default_address);
                    if(data.default_address == 1){
                        var html = '<div class="address manage-address" id="addr' + data.id + '"><div class="info">收货人：<p class="name">' + data.consignee + '</p><p class="phone">' + data.mobile + '</p>' +
                            '</div><div class="details">收货地址：' + data.province + data.city + data.country + data.detail + '</div><div class="address-bottom">' +
                            '<label><input type="radio" name="address" value="' + data.id + '" checked>默认收货地址</label><div class="operate "><a href="javascript:;"' +
                            ' class="j-address-edit edit" data-id="' + data.id + '">编辑</a>｜<a href="javascript:;" class="j-address-delete" onclick="delAddress(' + data.id + ')">删除</a>' +
                            '</div></div></div>';
                    }else{
                        var html = '<div class="address manage-address" id="addr' + data.id + '"><div class="info">收货人：<p class="name">' + data.consignee + '</p><p class="phone">' + data.mobile + '</p>' +
                            '</div><div class="details">收货地址：' + data.province + data.city + data.country + data.detail + '</div><div class="address-bottom">' +
                            '<label><input type="radio" name="address" value="' + data.id + '">默认收货地址</label><div class="operate "><a href="javascript:;"' +
                            ' class="j-address-edit edit" data-id="' + data.id + '">编辑</a>｜<a href="javascript:;" class="j-address-delete" onclick="delAddress(' + data.id + ')">删除</a>' +
                            '</div></div></div>';
                    }
                    ele.append(html);
                    $('.m-address').css('display','block');
                    $('.edit-address').css('display','none');
                    $('#actionBtn').text('新增收货地址');
                }else{
                    alert(data.message);
                }
            },
            error:function(error){
                console.log(error);
            }
        });
    }

    // 更新地址
    function updateAddress(data){
        $.ajax({
            type : 'post',
            dataType : 'json',
            url : '/myself/editAddress',
            data : data,
            success:function(data)
            {
				if(data.status){
                    clearAddress()
                    var data = data.data;
                    $("#addr" + data.id).find('.name').html(data.consignee);
                    $("#addr" + data.id).find('.phone').html(data.mobile);
                    $("#addr" + data.id).find('.details').html('收货地址：' + data.province + data.city + data.country + data.detail);
				}else{
				    alert(data.message);
				}
            },
            error:function(error){
                console.log(error);
            }
        });
    };

    // 编辑地址
    $('.edit').on('click',function(){
        if($('.m-address').is(':visible') && $('.edit-address').is(':hidden'))
        {
            $('.m-address').css('display','none');
            $('.edit-address').css('display','block');
            $('#actionBtn').text('编辑地址');
            var id = $(this).attr('data-id');
            $.ajax({
                type:"get",
                dataType:'json',
                data:{
					id : id
                },
                url:"/myself/detail",
                async:true,
                success:function(data){
					if(data){
					    $("input[name = 'addrId']").val(data.id);
                        $("#name").val(data.consignee);
                        $("#phone").val(data.mobile);
                        $("#J_Address").val(data.province + ' ' + data.city + ' ' + data.country);
                        $("#addressDetail").val(data.detail);
					}
                },
                error:function(error){
                    //异常处理；
                    console.log(error);
                }
            });
        }
    });

    // 删除地址
    function delAddress(id){
        var res = confirm('确定要删除收货地址吗?');
        if(res){
            $.ajax({
                type : 'get',
                dataType : 'json',
                url : '/myself/delAddr',
                data : {
                    'id' : id
                },
                success:function(data){
                    if(data.status){
                        $("#addr" + id).empty(); // 删除下面的所有子元素
                        $("#addr" + id).remove(); // 删除对象本身
                    }
                    else{
                        alert(data.message);
                    }
                },
                error:function(error){
                    console.log(error);
                }
            });
        }
    }

    // 选择收货地址处理
    $("input[type = 'radio']").on('click', function(){
        var id = $(this).val();
        changeAdder(id);
    });
    function changeAdder(id)
    {
        $.ajax({
            type : 'get',
            dataType : 'json',
            url : '/myself/changeAddress',
            data : {
                id : id,
                user_id : $("input[name='user_id']").val()
            },
            success : function(data){
                if(!data.status){
                    console.log('变更错误');
                }
            },
            error : function(error){
                console.log(error);
            }
        });
    }
</script>
<script>
    /**
     * 默认调用
     */
    !function () {
        var target = $('#J_Address');

        target.citySelect();

        target.on('click', function (event) {
            event.stopPropagation();
            target.citySelect('open');
        });

        target.on('done.ydui.cityselect', function (ret) {
            $(this).val(ret.provance + ' ' + ret.city + ' ' + ret.area);
        });
    }();
</script>
</body>
</html>
>>>>>>> 93c40d8086b7a8d5a9aa3548fdc8eb06a4272cf7
